#include <mpi.h>
#include <stdio.h>
#include "utils.h"

int main(int argc, char *argv[]) {
    MPI_Init(&argc, &argv);

    int world_rank, world_size;
    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);

    MPI_Comm parent_comm;
    MPI_Comm_get_parent(&parent_comm);

    if (parent_comm == MPI_COMM_NULL) {
        printf("Error: No parent communicator\n");
        MPI_Finalize();
        return 1;
    }

    // 接收来自父进程的消息
    int message;
    if (world_rank == 0)
        MPI_Recv(&message, 1, MPI_INT, 0, 0, parent_comm, MPI_STATUS_IGNORE);

    INFO("Child rank %d recv msg %d from parent process 0!\n", world_rank, message);

    MPI_Finalize();
    return 0;
}